<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue.js demo</title>
    <script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
    <input v-model="firstName"/><br/>
    <input v-model="lastName"/><br/>
    <input v-model="nickName"/><br/>

    <input v-model="fullName"><br/>

</div>
</body>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                firstName: 'helen',
                lastName: 'yao',
                nickName: ''
            }
        },
        methods: {},
        computed: {
            fullName: {
                get() {
                    return this.firstName + '-' + this.lastName
                },
                set(data) {
                    const strings = data.toString().split('-')
                    this.firstName = strings[0]
                    this.lastName = strings[1]
                }
            }
        },
        watch: {
            firstName(data) {
                console.log(data + ' firstName')
                this.nickName = this.fullName
            },
            lastName(data) {
                console.log(data + ' lastName')
                this.nickName = this.fullName
            },
            fullName(data) {
                console.log(data + ' fullName')
            },
            nickName(data) {
                const strings = data.toString().split('-');
                this.firstName = strings[0]
                this.lastName = strings[1]
            }
        }
    })

</script>
</html>
